package logic

import (
	"context"
	"strconv"

	"microdemo/service/user/internal/svc"
	"microdemo/service/user/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeletedUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDeletedUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeletedUserLogic {
	return &DeletedUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 根据 id 删除用户。设置无返回值
func (l *DeletedUserLogic) DeletedUser(in *user.IdRequest) (*user.Empty, error) {
	atoi, err := strconv.Atoi(in.Id)
	if err != nil {
		return nil, err
	}
	err = l.svcCtx.UserModel.Delete(l.ctx, int64(atoi))
	if err != nil {
		return nil, err
	}
	return &user.Empty{}, nil
}
